package struts.com;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import struts.bean.XmlBean;

public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO 自动生成的方法存根
		System.out.println("信息：context销毁");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		// TODO 自动生成的方法存根
		System.out.println("信息：context初始化");
		
		ServletContext context = arg0.getServletContext();
		
		String configname = context.getInitParameter("struts");
		String url =  context.getRealPath("\\");
		
		try {
//			String url =  context.getResource("\\").getPath();
			
			Map<String, XmlBean> configMap = StrutsConfig.strutsConfigXml(url + configname);
			
			context.setAttribute("struts-config", configMap);
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		
		System.out.println("信息：servlet加载完毕！");
	}

}
